package com.treeroot.planeservice.plane.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.treeroot.commonutils.result.R;
import com.treeroot.planeservice.plane.entity.PcTicketingInfo;
import com.treeroot.planeservice.plane.service.PcTicketingInfoService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author TreeRoot
 * @since 2022-06-12
 */
@RestController
@Api(description = "票务控制")
@RequestMapping("pc/plane/pcticketinginfo")
public class PcTicketingInfoController {
    @Autowired
    private PcTicketingInfoService ticketingInfoService;
    @PostMapping("add")
    public R addPcticketing(@RequestBody PcTicketingInfo ticketingInfo){
        ticketingInfoService.save(ticketingInfo);
        return R.ok();
    }
    @PostMapping("ticketingInfo/{current}/{limit}")
    public R ticketingInfo(@PathVariable long current, @PathVariable long limit,
                           @RequestBody(required = false) PcTicketingInfo ticketingInfo) {
        Page<PcTicketingInfo> ticketingInfoPage = new Page<>(current, limit);
        LambdaQueryWrapper<PcTicketingInfo> wrapper = new QueryWrapper<PcTicketingInfo>().lambda()
                .eq(!StringUtils.isEmpty(ticketingInfo.getFlightNumber()),
                        PcTicketingInfo::getFlightNumber,
                        ticketingInfo.getFlightNumber());
        ticketingInfoService.page(ticketingInfoPage, wrapper);
        long total = ticketingInfoPage.getTotal();
        List<PcTicketingInfo> list = ticketingInfoPage.getRecords();

        return R.ok().data("total", total).data("list", list);
    }

}

